package me.zhengjie.inter.rest;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import me.zhengjie.annotation.Log;
import me.zhengjie.aop.annotation.BisLog;
import me.zhengjie.business.domain.Zhsq;
import me.zhengjie.business.service.ZhsqService;
import me.zhengjie.business.service.dto.ZhsqQueryCriteria;
import me.zhengjie.inter.service.MpZhsqPgService;
import me.zhengjie.inter.service.MpZhsqService;
import me.zhengjie.utils.PageUtil;
import me.zhengjie.utils.SecurityUtils;
import org.springframework.data.domain.Pageable;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

/**
 * @author gongtuohao
 * @date 2022-07-22
 **/
@RestController
@RequiredArgsConstructor
@Api(tags = "移动端照护申请评估")
@RequestMapping("/mp/zhsqpg")
public class MpZhsqPgController {

    private final MpZhsqPgService mpZhsqPgService;
    private final ZhsqService zhsqService;
    private final MpZhsqService mpZhsqService;

    @GetMapping("/list")
    @ApiOperation("移动端查询居家照护评估")
    public ResponseEntity<Object> queryZhsq(ZhsqQueryCriteria criteria, Pageable pageable) {
        criteria.setSbgs(null);
        return new ResponseEntity<>(PageUtil.toMpContent(
                mpZhsqPgService.queryAllByPgUserId(
                        criteria.getBisZhsqZt().get(0),
                        SecurityUtils.getCurrentUserId(),
                        criteria.getBisZhsqZhlb(),
                        criteria.getBlurry(), pageable)), HttpStatus.OK);
    }

    @GetMapping("/findById")
    @ApiOperation("移动端查询居家照护评估")
    public ResponseEntity<Object> findById(Long id) {
        return new ResponseEntity<>(PageUtil.toMpContent(mpZhsqPgService.findById(id)), HttpStatus.OK);
    }


    @GetMapping("/findZhInfoAndAdlById")
    @ApiOperation("移动端查询居家照护评估")
    public ResponseEntity<Object> findZhInfoAndAdlById(Long id) {
        return new ResponseEntity<>(PageUtil.toMpContent(mpZhsqPgService.findZhInfoAndAdlById(id)), HttpStatus.OK);
    }


    @PostMapping(value = "/checkPgjjzh")
    @Log("手机端评估居家照护")
    @ApiOperation("手机端评估居家照护")
    public ResponseEntity<Object> checkPgjjzh(@RequestBody Zhsq resources){
        zhsqService.updateZhzt(resources.getBisZhsqZt(), resources.getBisZhsqId(), resources.getBz());
        return new ResponseEntity<>(PageUtil.toMpContent(new HashMap<String,Object>()),HttpStatus.OK);
    }

    @PostMapping(value = "/checkPgjgzh")
    @Log("手机端评估机构照护")
    @ApiOperation("手机端评估机构照护")
    public ResponseEntity<Object> checkPgjgzh(@RequestBody Zhsq resources){
        zhsqService.checkPgjgzh(resources.getBisZhsqZt(), resources.getBisZhsqId(), resources.getBz());
        return new ResponseEntity<>(PageUtil.toMpContent(new HashMap<String,Object>()),HttpStatus.OK);
    }

    @GetMapping(value = "/queryScore")
    @Log("评估ADL量表计算分数")
    @ApiOperation("评估ADL量表计算分数")
    public ResponseEntity<Object> queryScore(String[] adlIds){
        HashMap reMap = new HashMap<String,Object>();
        String fs = mpZhsqService.queryScore(adlIds);
        reMap.put("fs",fs);
        return new ResponseEntity<>(PageUtil.toMpContent(reMap),HttpStatus.OK);
    }

//
//    @PostMapping
//    @Log("移动端新增居家照护评估")
//    @ApiOperation("移动端新增居家照护评估")
//    public ResponseEntity<Object> createZhsq(@Validated @RequestBody Zhsq resources, @RequestParam String ids, HttpServletRequest request){
//        return new ResponseEntity<>(PageUtil.toMpContent(mpZhsqPgService.create(resources, ids)), HttpStatus.CREATED);
//    }

}
